package com.zzc.alfred.entity.service.mysql;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.zzc.alfred.entity.mapper.ProductIndexModelMapper;
import com.zzc.alfred.entity.model.ProductIndexModel;
import com.zzc.alfred.entity.util.DateUtil;
import com.zzc.alfred.entity.util.MyBatisUtil;

/**
 * 数据库查询
 * 
 * @author famous
 *
 */
public class ProductIndexModelDBService {

	/**
	 * 查询凌晨新增的数据记录准备进入索引
	 * 
	 * @return
	 */
	public List<ProductIndexModel> getAddedProduct() {
		List<ProductIndexModel> list = new ArrayList<ProductIndexModel>();
		SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
		try {
			ProductIndexModelMapper productIndexModelMapper = sqlSession.getMapper(ProductIndexModelMapper.class);
			list = productIndexModelMapper.getAddedProduct(DateUtil.getStandDate());
			sqlSession.commit();
		} finally {
			sqlSession.close();
		}
		return list;
	}

	public List<ProductIndexModel> getAddedProductFormMahout() {
		List<ProductIndexModel> list = new ArrayList<ProductIndexModel>();
		SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
		try {
			ProductIndexModelMapper productIndexModelMapper = sqlSession.getMapper(ProductIndexModelMapper.class);
			list = productIndexModelMapper.getAddedProductForMahout();
			sqlSession.commit();
		} finally {
			sqlSession.close();
		}
		return list;
	}

	public ProductIndexModel getProduct(String id) {
		ProductIndexModel model = null;
		SqlSession sqlSession = MyBatisUtil.getSqlSessionFactory().openSession();
		try {
			ProductIndexModelMapper productIndexModelMapper = sqlSession.getMapper(ProductIndexModelMapper.class);
			model = productIndexModelMapper.getProductByKey(id);
			sqlSession.commit();
		} finally {
			sqlSession.close();
		}
		return model;
	}

}
